/**
 * output package name
 */
package com.kingdee.eas.custom.basedata.client;

import java.awt.event.*;
import java.util.HashSet;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.data.event.RequestRowSetEvent;
import com.kingdee.bos.ctrl.kdf.table.util.KDTableUtil;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.basedata.assistant.app.F7ProjectUIHandler;
import com.kingdee.eas.basedata.framework.util.EntityControlTypeUtil;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupFactory;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardCollection;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardFactory;
import com.kingdee.eas.basedata.master.cssp.CSSPGroupStandardInfo;
import com.kingdee.eas.basedata.master.cssp.ICSSPGroupStandard;
import com.kingdee.eas.basedata.master.cssp.StandardTypeEnum;
import com.kingdee.eas.basedata.master.cssp.SupplierFactory;
import com.kingdee.eas.basedata.master.cssp.SupplierInfo;
import com.kingdee.eas.basedata.master.cssp.client.F7SupplierSimpleSelector;
import com.kingdee.eas.basedata.master.cssp.client.F7SupplierSimpleTreeDetailListUI;
import com.kingdee.eas.basedata.master.material.client.F7BaseUI;
import com.kingdee.eas.basedata.master.material.client.IF7InnerUI;
import com.kingdee.eas.basedata.org.CtrlUnitInfo;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.framework.*;
import com.kingdee.eas.framework.client.tree.KDTreeNode;
import com.kingdee.eas.framework.util.FilterUtility;
import com.kingdee.eas.util.client.EASResource;

/**
 * output class name
 */
public class F7ProjectSimpleTreeDetailListUI extends AbstractF7ProjectSimpleTreeDetailListUI  implements IF7InnerUI
{
	 	
	public F7ProjectSimpleTreeDetailListUI() throws Exception {
		super();
	}
	           public static final String SELECTOR = "selector";
			   public static final String TREE_FILTER = "treeFilter";
			   private CtrlUnitInfo curCtrlUnitInfo;
			   public static final String CTX_CU = "cu";
               private static final Logger logger = CoreUIObject.getLogger(F7ProjectSimpleTreeDetailListUI.class);
    
               private boolean isQuickQuery = false;

               private FilterInfo userBaseFilterInfo = null;
    
               private FilterInfo userTreeFilterInfo = null;
               private boolean isMulSelect = false;
			private String groupStandardID;			
			
    
               public void onLoad() throws Exception { 
            	  F7SupplierSimpleSelector selector = null;
    /*  81 */     this.curCtrlUnitInfo = ((CtrlUnitInfo)getUIContext().get("cu"));
    /*  82 */     if (this.curCtrlUnitInfo == null) {
    /*  83 */       this.curCtrlUnitInfo = getPromptBox().getCurrentCtrlUnit();
    /*     */     }
    /*     */ 
    /*  86 */     if (this.curCtrlUnitInfo == null) {
    /*  87 */       this.curCtrlUnitInfo = SysContext.getSysContext().getCurrentCtrlUnit();
    /*     */
    /*     */     }
    /*     */ 
    /*  91 */     if (getParentUI().getUIContext().containsKey("selector")) {
    /*  92 */       selector = (F7SupplierSimpleSelector)getParentUI().getUIContext().get("selector");
    /*     */ 
    /*  94 */       this.isMulSelect = selector.isMulSelect();
    /*     */
    /*     */     }
    /*     */ 
    /*  98 */     if ((selector != null) && (selector.getBaseFilter() != null)) {
    /*  99 */       this.userBaseFilterInfo = selector.getBaseFilter();
    /*     */
    /*     */     }
    /*     */ 
    /* 103 */     if ((selector != null) && (selector.getTreeFilter() != null)) {
    /* 104 */       this.userTreeFilterInfo = selector.getTreeFilter();
    /*     */
    /*     */     }
    /*     */ 
    /* 108 */     FilterInfo userGroupStandardFilter = null;
    /* 109 */     if ((selector != null) && (selector.getGroupStandardFilter() != null))
    /* 110 */       userGroupStandardFilter = selector.getGroupStandardFilter();
    /*     */     else {
    /* 112 */       userGroupStandardFilter = EntityControlTypeUtil.getFilterInfoForControlTypeS4(this.curCtrlUnitInfo.getId().toString(), this.curCtrlUnitInfo.getLongNumber());
    /*     */
    /*     */
    /*     */     }
    /*     */ 
    /* 117 */     loadGroupStandard(userGroupStandardFilter);
    /* 118 */     super.onLoad();
    /* 119 */     if (this.isMulSelect)
    /* 120 */       this.tblMain.getSelectManager().setSelectMode(10);
    /*     */     else {
    /* 122 */       this.tblMain.getSelectManager().setSelectMode(2);
    /*     */     }
    /* 124 */     this.treeView.setShowControlPanel(false);
    /* 125 */     ItemListener groupStandardListener = new ItemListener() {
    	
    /*     */       public void itemStateChanged(ItemEvent e) {
    /* 127 */         F7ProjectSimpleTreeDetailListUI.this.groupStandardChanged(e);
    /*     */       }
    /*     */     };
    /* 130 */     this.comboGroupStandard.addItemListener(groupStandardListener);
    /* 131 */     groupStandardChanged(null);
    /*     */   }
    /*     */
    /*     */   public KDBizPromptBox getPromptBox() {
    /* 135 */     return getParentUI().getPromptBox();
    /*     */   }
    /*     */
    /*     */   private void groupStandardChanged(ItemEvent e)
    /*     */   {
    /*     */     try {
    /* 141 */       CSSPGroupStandardInfo standardInfo = (CSSPGroupStandardInfo)this.comboGroupStandard.getSelectedItem();
     				
    /* 142 */       this.groupStandardID = standardInfo.getId().toString();
    /* 143 */       initTree();
    /*     */     } catch (Exception ex) {
    /* 145 */       ex.printStackTrace();
    /*     */     }
    /*     */   }
    /*     */
    /*     */   private void loadGroupStandard(FilterInfo groupStandardFilter) throws Exception
    /*     */   {
    /* 151 */     EntityViewInfo viewInfo = new EntityViewInfo();
    /* 152 */     viewInfo.setFilter(groupStandardFilter);
    /* 153 */     ICSSPGroupStandard iCSSPGroupStandard = CSSPGroupStandardFactory.getRemoteInstance();
    /* 154 */     CSSPGroupStandardCollection groupStandardColl = iCSSPGroupStandard.getCSSPGroupStandardCollection(viewInfo);
    /*     */ 
    /* 156 */     this.comboGroupStandard.removeAllItems();
    /* 157 */     if (groupStandardColl != null) {
    /* 158 */       this.comboGroupStandard.addItems(groupStandardColl.toArray());
    /*     */     }
    /*     */ 
    /* 161 */     int size = groupStandardColl.size();
    /* 162 */     for (int index = 0; index < size; ++index) {
    /* 163 */       CSSPGroupStandardInfo cSSPGroupStandardInfo = groupStandardColl.get(index);
    /* 164 */       if (cSSPGroupStandardInfo.getIsBasic() == StandardTypeEnum.basicStandard) {
    /* 165 */         this.comboGroupStandard.setSelectedIndex(index);
    /* 166 */         return;
    /*     */       }
    /*     */     }
    /*     */   }
    /*     */
    /*     */   protected BOSObjectType getBizObjectType()
    /*     */   {
    /* 173 */     BOSObjectType bosType = BOSObjectType.create("4409E7F0");
    /* 174 */     return bosType;
    /*     */   }
    /*     */
    /*     */   protected String getKeyFieldName() {
    /* 178 */     return "id";
    /*     */   }
    /*     */
    /*     */   protected FilterInfo getGroupStandardFilter() {
    /* 182 */     FilterInfo groupStandardFilter = new FilterInfo();
    /* 183 */     groupStandardFilter.getFilterItems().add(new FilterItemInfo("groupStandard.id", this.groupStandardID, CompareType.EQUALS));
    /*     */ 
    /* 185 */     return groupStandardFilter;
    /*     */   }
    /*     */
    /*     */
    /*     */   protected FilterInfo getDefaultFilterForTree()
    /*     */   {
    /* 191 */     FilterInfo filterInfo = getGroupStandardFilter();
    /* 192 */     FilterInfo tempFilterInfo = null;
    /* 193 */     if (this.userTreeFilterInfo != null)
    /* 194 */       tempFilterInfo = this.userTreeFilterInfo;
    /*     */     else {
    /* 196 */       tempFilterInfo = EntityControlTypeUtil.getFilterInfoForControlTypeS4(this.curCtrlUnitInfo.getId().toString(), this.curCtrlUnitInfo.getLongNumber());
    /*     */     }
    /*     */ 
    /*     */     try
    /*     */     {
    /* 201 */       filterInfo.mergeFilter(tempFilterInfo, "and");
    /*     */     } catch (BOSException e) {
    /* 203 */       e.printStackTrace();
    /*     */     }
    /* 205 */     return filterInfo;
    /*     */   }
    /*     */
    /*     */   private FilterInfo getBaseFilter()
    /*     */   {
    /* 210 */     if (this.userBaseFilterInfo != null) {
    /* 211 */       return this.userBaseFilterInfo;
    /*     */     }
    /*     */ 
    /* 214 */     return this.cStrategy.getDefaultFilterForControlType();
    /*     */   }
    /*     */
    /*     */   protected String getRootName() {
    	
    				return "项目表";
    	
    /*     */   }
    /*     */
    /*     */   public F7BaseUI getParentUI() {
    /* 222 */     return ((F7BaseUI)getParent().getParent());
    /*     */   }
    /*     */
    /*     */
    /*     */
    /*     */   protected void tblMain_doRequestRowSet(RequestRowSetEvent e)
    /*     */   {
    /*     */     try
    /*     */     {
    /* 231 */       this.mainQuery = getDefaultQuery();
    /* 232 */       super.tblMain_doRequestRowSet(e);
    /*     */     } catch (Exception ee) {
    /* 234 */       handUIException(ee);
    /*     */     }
    /*     */   }
    /*     */
    /*     */   protected FilterInfo getTreeFilter()
    /*     */   {
    /* 240 */     FilterInfo cuFilter = new FilterInfo();
    /*     */ 
    /* 242 */     CSSPGroupStandardInfo info = (CSSPGroupStandardInfo)this.comboGroupStandard.getSelectedItem();
    /* 243 */     boolean isBaseStardarGroupStandard = info.getIsBasic() == StandardTypeEnum.basicStandard;
    /* 244 */     String groupStandardID = info.getId().toString();
    /*     */ 
    /* 246 */     if (this.chkIncludeChild.isSelected()) {
    /* 247 */       TreeBaseInfo tree = getSelectTreeInfo();
    /* 248 */       String longNumber = (tree == null) ? "" : tree.getLongNumber();
    /* 249 */       FilterInfo tempFilter = new FilterInfo();
    /* 250 */       if ((longNumber != null) && (longNumber.length() > 0))
    /* 251 */         if (isBaseStardarGroupStandard) {
    /* 252 */           tempFilter.getFilterItems().add(new FilterItemInfo("browseGroup.longNumber", longNumber + "!" + "%", CompareType.LIKE));
    /*     */
    /* 256 */           tempFilter.getFilterItems().add(new FilterItemInfo("browseGroup.longNumber", longNumber, CompareType.EQUALS));
    /* 257 */           tempFilter.setMaskString("#0 OR #1");
    /*     */         } else {
    /* 259 */           StringBuffer sb = new StringBuffer();
    /* 260 */           sb.append("select gd.fsupplierid from T_BD_SupplierGroupDetail gd , T_BD_CsspGroup g  where 1=1");
    /* 261 */           sb.append(" and ( g.flongnumber like '" + longNumber + "!" + "%" + "' ");
    /* 262 */           sb.append(" or g.flongnumber='" + longNumber + "' )");
    /* 263 */           sb.append(" and  G.FID = GD.FSUPPLIERID ");
    /* 264 */           tempFilter.getFilterItems().add(new FilterItemInfo("id", sb.toString(), CompareType.INNER));
    /*     */         }
    /*     */       try
    /*     */       {
    /* 268 */         if (FilterUtility.hasFilterItem(cuFilter))
    /* 269 */           cuFilter.mergeFilter(tempFilter, "AND");
    /*     */         else
    /* 271 */           cuFilter = tempFilter;
    /*     */       }
    /*     */       catch (BOSException e) {
    /* 274 */         e.printStackTrace();
    /* 275 */         logger.debug("merge tree error for inlude child !", e);
    /* 276 */         handleException(e);
    /*     */       }
    /* 278 */       this.mainQuery.setFilter(cuFilter);
    /*     */     } else {
    /* 280 */       TreeBaseInfo tree = getSelectTreeInfo();
    /* 281 */       if (tree == null) {
    /* 282 */         if (isBaseStardarGroupStandard) {
    /* 283 */           cuFilter.getFilterItems().add(new FilterItemInfo("id", "null"));
    /*     */         } else {
    /* 285 */           StringBuffer sb = new StringBuffer();
    /* 286 */           sb.append(" select gd.FSupplierID from T_BD_SupplierGroupDetail gd ");
    /* 287 */           sb.append(" where gd.FSUPPLIERGROUPSTANDARDID='" + groupStandardID + "'");
    /* 288 */           cuFilter.getFilterItems().add(new FilterItemInfo("id", sb.toString(), CompareType.NOTINNER));
    /*     */         }
    /*     */       }
    /* 291 */       else if (isBaseStardarGroupStandard) {
    /* 292 */         cuFilter.getFilterItems().add(new FilterItemInfo("browseGroup.id", tree.getId().toString()));
    /*     */       } else {
    /* 294 */         StringBuffer sb = new StringBuffer();
    /* 295 */         sb.append(" select gd.fsupplierid from T_BD_SupplierGroupDetail gd ");
    /* 296 */         sb.append(" where gd.FSupplierGroupID='" + tree.getId().toString() + "'");
    /* 297 */         sb.append(" and gd.FSupplierGroupStandardID='" + groupStandardID + "'");
    /* 298 */         cuFilter.getFilterItems().add(new FilterItemInfo("id", sb.toString(), CompareType.INNER));
    /*     */       }
    /*     */ 
    /*     */     }
    /*     */ 
    /* 303 */     return cuFilter;
    /*     */   }
    /*     */
    /*     */   protected EntityViewInfo getDefaultQuery()
    /*     */   {
    /* 308 */     EntityViewInfo evi = new EntityViewInfo();
    /* 309 */     evi.setFilter(getDefaultFilterForQuery());
    /* 310 */     evi.getSorter().clear();
    /* 311 */     evi.getSorter().addObjectCollection(this.mainQuery.getSorter());
    /* 312 */     return evi;
    /*     */   }
    /*     */
    /*     */   protected FilterInfo getDefaultFilterForQuery()
    /*     */   {
    /* 317 */     FilterInfo filterInfo = null;
    /*     */     try {
    /* 319 */       if (this.isQuickQuery) {
    /* 320 */         filterInfo = getQuickFilter();
    /* 321 */         filterInfo.mergeFilter(getBaseFilter(), "and");
    /*     */       } else {
    /* 323 */         filterInfo = getTreeFilter();
    /* 324 */         filterInfo.mergeFilter(getBaseFilter(), "and");
    /*     */       }
    /*     */     } catch (BOSException e) {
    /* 327 */       e.printStackTrace();
    /*     */     }
    /* 329 */     return filterInfo;
    /*     */   }
    /*     */
    /*     */   private FilterInfo getQuickFilter()
    /*     */   {
    /* 334 */     FilterInfo quickFilter = getParentUI().getQuickFilter();
    /* 335 */     return quickFilter;
    /*     */   }
    /*     */
    /*     */   private TreeBaseInfo getSelectTreeInfo() {
    /* 339 */     KDTreeNode treeNode = getSelectedTreeNode();
    /* 340 */     if ((treeNode != null) && (treeNode.getUserObject() instanceof TreeBaseInfo))
    /*     */     {
    /* 342 */       return ((TreeBaseInfo)treeNode.getUserObject());
    /*     */     }
    /* 344 */     return null;
    /*     */   }
    /*     */
    /*     */   public void actionView_actionPerformed(ActionEvent e)
    /*     */     throws Exception
    /*     */   {
    /* 350 */     getParentUI().actionConfirm_actionPerformed(null);
    /*     */   }
    /*     */
    /*     */   protected IObjectPK getSelectedTreeKeyValue()
    /*     */   {
    /* 355 */     return null;
    /*     */   }
    /*     */
    /*     */   protected ITreeBase getTreeInterface() throws Exception {
    /* 359 */     return CSSPGroupFactory.getRemoteInstanceWithObjectContext(getMainOrgContext());
    /*     */   }
    /*     */
    /*     */   public boolean confirmCheck()
    /*     */   {
    /* 364 */     int[] selectRows = KDTableUtil.getSelectedRows(this.tblMain);
    /* 365 */     if (selectRows.length < 1)
    /* 366 */       return false;
    /*     */     try
    /*     */     {
    /* 369 */       ICoreBase iBiz = getBizInterface();
    /* 370 */       if (this.isMulSelect) {
    /* 371 */         SupplierInfo[] supplierInfos = new SupplierInfo[selectRows.length];
    /* 372 */         HashSet idSet = new HashSet();
    /*     */ 
    /* 374 */         for (int i = 0; i < selectRows.length; ++i) {
    /* 375 */           String id = this.tblMain.getRow(selectRows[i]).getCell("id").getValue().toString();
    /* 376 */           idSet.add(id);
    /*     */         }
    /* 378 */         EntityViewInfo view = new EntityViewInfo();
    /* 379 */         FilterInfo filter = new FilterInfo();
    /* 380 */         filter.getFilterItems().add(new FilterItemInfo("id", idSet, CompareType.INCLUDE));
    /* 381 */         view.setFilter(filter);
    /* 382 */         CoreBaseCollection coll = iBiz.getCollection(view);
    /* 383 */         for (int j = 0; j < coll.size(); ++j) {
    /* 384 */           supplierInfos[j] = ((SupplierInfo)coll.get(j));
    /*     */         }
//    /* 386 */         this.f7Value = supplierInfos;
    /*     */       } else {
    /* 388 */         String id = this.tblMain.getRow(selectRows[0]).getCell("id").getValue().toString();
    /*     */         try {
    /* 390 */           ObjectUuidPK pk = new ObjectUuidPK(BOSUuid.read(id));
//    /* 391 */           this.f7Value = iBiz.getValue(pk);
    /*     */         } catch (Exception er) {
    /* 393 */           super.handUIException(er);
    /*     */         }
    /*     */       }
    /* 396 */       return true;
    /*     */     } catch (Exception e) {
    /* 398 */       e.printStackTrace();
    /*     */     }
    /* 400 */     return false;
    /*     */   }
    /*     */
    /*     */   protected ICoreBase getBizInterface() throws Exception
    /*     */   {
    /* 405 */     return SupplierFactory.getRemoteInstanceWithObjectContext(getMainOrgContext());
    /*     */   }
    /*     */
//    /*     */   public Object getData() {
//    /* 409 */     return this.f7Value;
//    /*     */   }
//    /*     */
    /*     */
    /*     */
    /*     */
    /*     */
    /*     */
    /*     */
    /*     */
    /*     */
    /*     */   public void quickQuery() throws Exception {
    /* 421 */     this.isQuickQuery = true;
    /*     */     try {
    /* 423 */       execQuery();
    /*     */     } finally {
    /* 425 */       this.isQuickQuery = false;
    /*     */     }
    /*     */   }
    /*     */
    /*     */   public void refresh() throws Exception {
    /* 430 */     execQuery();
    /*     */   }
    /*     */
    /*     */   protected String getGroupEditUIName()
    /*     */   {
    /* 435 */     return null;
    /*     */   }
    /*     */
    /*     */   protected String getQueryFieldName() {
    /* 439 */     return "browseGroup.id";
    /*     */   }
	@Override
	public void maintenance() throws Exception {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void query() throws Exception {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Object getData() {
		// TODO Auto-generated method stub
		return null;
	}

}